/**
 * 并发编程
 * detach: 分离
 * 主线程不和子线程会合, 主线程关闭不影响子线程执行
 * detach 后主线程和子线程失去关联关系
 * 子线程完成后由C++运行时负责回收资源
 */
#include <thread>
#include <iostream>

void hello() {
    std::cout << "Hello Concurrent!" << "\n";
    std::cout << "Hello 1" << "\n";
    std::cout << "Hello 2" << "\n";
    std::cout << "Hello 3" << "\n";
    std::cout << "Hello 4" << "\n";
    std::cout << "Hello 5" << "\n";
    std::cout << "Hello 6" << "\n";
}

int main() {
    std::thread t(hello);
    std::cout << "finish 1" << std::endl;
    t.detach(); // 阻塞主线程，等待 hello 函数执行
    std::cout << "finish 2" << std::endl;
    return 0;
}